﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace MVCBugTracker.Areas.UserManagement.Models
{
    public class RoleService : IRoleService
    {
        private readonly RoleProvider Provider;

        public RoleService() : this(null) { }

        public RoleService(RoleProvider provider)
        {
            Provider = provider ?? Roles.Provider;
        }

        public string ApplicationName
        {
            get
            {
                return Provider.ApplicationName;
            }
            set
            {
                Provider.ApplicationName = value;
            }
        }

        public void AddUsersToRole(string[] userNames, string roleName)
        {
            string[] roles = new string[1];
            roles[0] = roleName;
            this.AddUsersToRoles(userNames, roles);
        }

        public void AddUsersToRoles(string[] userNames, string[] roleNames)
        {
            Provider.AddUsersToRoles(userNames, roleNames);
        }

        public void AddUserToRole(string userName, string roleName)
        {
            string[] users = new string[1];
            users[0] = userName;
            this.AddUsersToRole(users, roleName);
        }

        public void AddUserToRoles(string userName, string[] roleNames)
        {
            string[] users = new string[1];
            users[0] = userName;
            this.AddUsersToRoles(users, roleNames);
        }

        public void CreateRole(string roleName)
        {
            Provider.CreateRole(roleName);
        }

        public bool DeleteRole(string roleName)
        {
            return this.DeleteRole(roleName, true);
        }

        public bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            return Provider.DeleteRole(roleName, throwOnPopulatedRole);
        }

        public string[] FindUsersInRole(string roleName, string userNameToMatch)
        {
            return Provider.FindUsersInRole(roleName, userNameToMatch);
        }

        public string[] GetAllRoles()
        {
            return Provider.GetAllRoles();
        }

        public string[] GetRolesForUser(string userName)
        {
            return Provider.GetRolesForUser(userName);
        }

        public string[] GetUsersInRole(string roleName)
        {
            return Provider.GetUsersInRole(roleName);
        }

        public bool IsUserInRole(string userName, string roleName)
        {
            return Provider.IsUserInRole(userName, roleName);
        }

        public void RemoveUserFromRole(string userName, string roleName)
        {
            string[] roles = new string[1];
            roles[0] = roleName;
            this.RemoveUserFromRoles(userName, roles);
        }

        public void RemoveUserFromRoles(string userName, string[] roleNames)
        {
            string[] users = new string[1];
            users[0] = userName;
            this.RemoveUsersFromRoles(users, roleNames);
        }

        public void RemoveUsersFromRole(string[] userNames, string roleName)
        {
            string[] roles = new string[1];
            roles[0] = roleName;
            this.RemoveUsersFromRoles(userNames, roles);
        }

        public void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
        {
            Provider.RemoveUsersFromRoles(userNames, roleNames);
        }

        public bool RoleExists(string roleName)
        {
            return Provider.RoleExists(roleName);
        }
    }
}